<template>
    <div :class="{ 'myPopup': !visible, 'myPopup_active': visible }" @click="close">
        <!-- <div class="myPopupBox" > -->
        <div :class="{ 'box': !visible, 'box_active': visible }" @click.stop :style="{ alignItems: position, }">
            <slot></slot>
        </div>
        <!-- </div> -->
    </div>
</template>

<script>
import { httpService } from "@/utils/httpService";
import { formatTime1 } from "@/utils/dateFormat";

export default {
    props: {
        visible: {
            type: Boolean,
            default: false
        },
        position: {
            type: Boolean,
            default: false
        },
    },
    data() {
        return {
            // visible: false,
            visiFlag: false,
            queryData: {},
            approveData: [],
        };
    },
    components: {

    },
    watch: {
        close() {
            this.$emit('update:popupFalg', false);
        },
        visible(val) {
            if (val) {
                this.disableScroll();
            } else {
                this.enableScroll();
            }
        }
    },
    mounted() {

    },
    methods: {
        disableScroll() {
            // 获取当前滚动条宽度
            const scrollBarWidth = window.innerWidth - document.documentElement.clientWidth;
            // 禁用页面滚动，并设置补偿的 padding-right
            document.body.style.overflow = 'hidden';
            // console.log(document.body);
            document.body.style.paddingRight = `${scrollBarWidth}px`;
        },
        enableScroll() {
            // 恢复页面滚动，并移除 padding-right
            document.body.style.overflow = '';
            document.body.style.paddingRight = '';
        },
        close() {

            this.$emit("close");
        },

    }
}
</script>

<style scoped>
* {
    margin: 0;
    padding: 0;
}

.flex {
    display: flex;
    align-items: center;
}

.myPopup {
    width: 100vw;
    min-height: 100vh;
    background-color: rgba(0, 0, 0, 0.5);
    position: fixed;
    left: 0;
    right: 0;
    top: 0;
    bottom: 0;
    z-index: -1;
    opacity: 0;

    transition: all 0.3s ease;
    /* overflow: hidden; */
}

.myPopup_active {
    width: 100vw;
    min-height: 100vh;
    background-color: rgba(0, 0, 0, 0.5);
    position: fixed;
    left: 0;
    right: 0;
    top: 0;
    bottom: 0;
    z-index: 999;
    opacity: 1;
    transition: all 0.3s ease;
    display: flex;
    /* align-items: center; */
    justify-content: center;
    overflow: auto;
}

.myPopupBox {
    background-color: brown;
}

.box {
    padding: 100px 0;
    display: flex;
    justify-content: center;
    transform: scale(0);
}

.box_active {
    padding: 100px 0;
    display: flex;
    justify-content: center;
    transform: scale(1);
}
</style>